<template>
		<uni-file-picker v-model="fileList" fileMediatype="image" mode="grid" @select="handleSelect"
			@delete="handleDelete" />
</template>

<script setup>
	import {
		computed,
		onMounted,
		reactive,
		watch,
		ref,
		watchEffect
	} from 'vue'
	import {
		isEmpty,
		isArray,
		cloneDeep,
		concat,
		isNumber,
		clone,
		forEach
	} from 'lodash-es'
	import sheep from '@/sheep'
	const props = defineProps({
		modelValue: {
			type: Object,
			default: () => {}
		}
	})

	const emit = defineEmits(['update:modelValue'])

	const fileList = ref([])

	watch(()=>fileList.value,(val)=>{
		if(isArray(val)){
			 emit('update:modelValue',val.map(el=>el.id))
		}
	},{
		immediate:true,
		deep:true
	})

	const handleSelect = ({
		tempFilePaths,
		tempFiles
	}) => {
		console.log('选择文件：', tempFilePaths, tempFiles)
		tempFilePaths.forEach(async el => {
			try{
				const res = await sheep.$api.common_system.upload(el)
				fileList.value.push({
					...res.data,
					name:res.data.id,
				})
			}catch(e){
			}
		})
	}
	const handleDelete = (e) => {

	}
</script>

<style>
</style>